//
//  NetWork.m
//  MyProject
//
//  Created by dllo on 15/11/11.
//  Copyright (c) 2015年 蓝鸥0825. All rights reserved.
//

#import "NetWork.h"

@implementation NetWork

+ (void)netWork:(id)controller{
    
    //      判断当前网络情况
    AFNetworkReachabilityManager * manager = [ AFNetworkReachabilityManager sharedManager];
    
    //      开始检测
    [manager startMonitoring];
    
    //       block 返回一个参数, 用这个参数判断网络状态
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        
        if (status == 1) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"当前网络为移动网络" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
        }];
            
        [alert addAction:ok];
        [controller presentViewController:alert animated:YES completion:^{
            
        }];
        
    } else if (status == 2) {
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"当前网络为Wifi" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
        }];
        
        [alert addAction:ok];
        [controller presentViewController:alert animated:YES completion:^{
            
        }];
        
        
    } else {
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"当前无网络" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
        }];
        
        [alert addAction:ok];
        [controller presentViewController:alert animated:YES completion:^{
            
        }];
        
    }
     
     NSLog(@"%ld", (long)status);
    }];
    
    [manager stopMonitoring];

}


@end
